// itemdata pdf
#ifndef _GEN_TEXT_PDF_HPP_
#define _GEN_TEXT_PDF_HPP_

#include "itemdata.hpp"
#include <cmath>
#include <cairo.h>
#include <cairo-pdf.h>

// here everything in pixel unit!!!

class text_pdf:public xlider_generator {
		
public:
	
	void create_bullet(cairo_t *cr){
		double r,g,b;
		if(get_bullet_type()!=""&&get_bullet_type()!="none") { 
			convert_color(get_bullet_color(),r,g,b);
			cairo_set_source_rgb(cr, r,g,b);
			double bx=get_x()+get_offsetx();
			double by=get_y()+get_offsety()-get_fontsize()/4.0;
			cairo_move_to(cr, bx, by);
			cairo_arc(cr,bx,by,get_bullet_radius(),0.0,2.0*M_PI);
			cairo_fill(cr);			
			set_width(it->width-get_line_offset()); 
		}
	}
	
	// returns height of object
	virtual double draw(void* draw_param) {
		cairo_t *cr=(cairo_t*) draw_param;
		double r,g,b;

		if(it->text.empty()) return 0.0;

		create_bullet(cr);
		arrange_text();
		xml_config_reader xfont(get_font_xml(get_fontname()).c_str());
		
		string fontfam(xfont.GetString("font.cairo.family"));
		string fontslant(xfont.GetString("font.cairo.slant"));
		string fontweight(xfont.GetString("font.cairo.weight"));
		
		cairo_font_slant_t fslant;
		cairo_font_weight_t fweight;
		
		if(fontslant=="normal") fslant=CAIRO_FONT_SLANT_NORMAL;
		if(fontslant=="italic") fslant=CAIRO_FONT_SLANT_ITALIC;
		if(fontslant=="oblique") fslant=CAIRO_FONT_SLANT_OBLIQUE;
		if(fontweight=="normal") fweight=CAIRO_FONT_WEIGHT_NORMAL;
		if(fontweight=="bold") fweight=CAIRO_FONT_WEIGHT_BOLD;

		convert_color(get_fontcolor(),r,g,b);
        cairo_select_font_face (cr, fontfam.c_str(), fslant, fweight);  
        cairo_set_font_size (cr, get_fontsize());
		cairo_set_source_rgb(cr, r,g,b);
		cairo_text_extents_t extent;

		for(int i=0;i<lines.size();i++){
			cairo_text_extents(cr, lines[i].c_str(), &extent);
			double tx=get_x()+get_shiftx(extent.width);
			double ty=get_y()+get_shifty(i);
			cairo_move_to(cr, tx,ty);
			cairo_show_text(cr, lines[i].c_str());
		}

		return get_actual_height();
	}

	virtual void* generate(void* param=NULL){
		set_height(draw(param));
		return param;
	}

};

#endif
